import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_yres/tool/constant.dart';
// ignore: must_be_immutable
class NetLoadingDialog extends StatefulWidget {
  String loadingText;
  bool outsideDismiss;
  Function dismissCallback;
  Future<dynamic> requestCallBack;
  Color bgColor;
  NetLoadingDialog(
      {Key key,
        this.loadingText = "loading...",
        this.outsideDismiss = true,
        this.dismissCallback,
        this.bgColor=Colors.white,
        this.requestCallBack})
      : super(key: key);

  @override
  State<NetLoadingDialog> createState() => _LoadingDialog();
}

class _LoadingDialog extends State<NetLoadingDialog> {
  // _dismissDialog() {
  //   if (widget.dismissCallback != null) {
  //     widget.dismissCallback();
  //   }
  //   Navigator.of(context).pop();
  // }

  @override
  void initState() {
    super.initState();
    if (widget.requestCallBack != null) {
      widget.requestCallBack.then((_) {
        Navigator.pop(context);
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return new GestureDetector(
      // onTap: widget.outsideDismiss ? _dismissDialog : null,
      child: Material(
        type: MaterialType.transparency,
        child: new Center(
          child: new SizedBox(
            width: ScreenUtil.getInstance().setWidth(DP_160),
            height: ScreenUtil.getInstance().setWidth(DP_160),
            child: new Container(
              decoration: ShapeDecoration(
                color: widget.bgColor,
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.all(
                    Radius.circular(8.0),
                  ),
                ),
              ),
              child: new Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
                  new CircularProgressIndicator(
                    backgroundColor: mainColor,
                    valueColor: new AlwaysStoppedAnimation<Color>(Colors.black),
                  ),
                  new Padding(
                    padding: const EdgeInsets.only(
                      top: 5.0,
                    ),
                    child: new Text(
                      widget.loadingText,
                      style: new TextStyle(fontSize: ScreenUtil.getInstance().setSp(SMALL_FONT_SIZE),color: Colors.white),
                    ),
                  ),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}